vim9script

if exists("g:linevim")
	finish
endif

g:linevim = 1

def g:MyTabLabel(n: number): string
	var sign: string
	var tabstr: string = expand($"#{tabpagebuflist(n)[0]}:t") ?? '[No Name]'

	if tabstr =~ 'bash (\d\+)'
		tabstr = 'bash'
	endif

	if tabstr != 'bash' && gettabwinvar(n, 1, '&modified')
		sign = '+ '
	endif

	return $" {n} {tabstr} {sign}"
enddef

def g:MyTabLine(): string
	var s = ''
	var current: number = tabpagenr()
	var total: number = tabpagenr('$')

	for i in range(1, total)
		if i == current
			s ..= '%#TabLineSel#'
		else
			s ..= '%#TabLine#'
		endif

		s ..= $"%\{MyTabLabel({i})\}|"
	endfor

	return s[: -2] .. "%#TabLineFill#"
enddef
set tabline=%!MyTabLine()

def g:MyTabPanel(): string
	return printf($"%2d {getbufvar(tabpagebuflist(g:actual_curtabpage)[0], "&buftype") ?? "%%t"} %%M",
		g:actual_curtabpage)
enddef
set tabpanel=%!MyTabPanel()

def g:LineUpdate(): string
	return $"%\{mode()\} | %\{expand('%:~:.') ?? '[No Name]'\} %\{&paste ? '| paste' : ''\}%M %= %\{&ff\} | %\{&ft ?? 'no ft'\} | %P"
enddef
set statusline=%!LineUpdate()
